﻿using Furion.DynamicApiController;
using Furion.UnifyResult;
using Microsoft.AspNetCore.Mvc;
using MSEAP.Entitys;
using SqlSugar;

namespace MSEAP.Controllers
{
    [DynamicApiController]

    [ApiDescriptionSettings(Order = 1000)]
    public class InitController
    {
        private readonly ILogger<InitController> logger;
        private readonly ISqlSugarClient db;

        public InitController(ILogger<InitController> logger, ISqlSugarClient db)
        {
            this.db = db;
            this.logger = logger;
        }

        public async Task<IActionResult> Index()
        {
            db.CodeFirst.InitTables<UserEntity>();
            db.CodeFirst.InitTables<ProjectEntity>();

            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = db.DbMaintenance.GetTableInfoList(false),
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }

        public async Task<IActionResult> List()
        {
            return new JsonResult(new RESTfulResult<object>
            {
                StatusCode = 200,
                Succeeded = true,
                Data = db.DbMaintenance.GetTableInfoList(false),
                Errors = null,
                Extras = UnifyContext.Take(),
                Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
            });
        }
    }
}
